<template>
  <tl-sub-page :render="render" ref="drawerRef" :visible.sync="visible" :with-header="false" :modal-append-to-body="true" :close-on-press-escape="false" :append-to-body="true" class="tl-drawer editPage" :size="'95%'" @open="open" @close="close" :destroy-on-close="true">
    <div class="mpm-project-container">
      <div style="width:0px;overflow:hidden;height:0px;"><input type="text" /></div>
      <div class="mpm-project-header">
        <div class="info">
          <img src="/static/images/paojectManager/mpm_universalChange_edit.png" class="logo" style="width: 55px;height: 55px" />
          <div class="content">
            <p>
              <b v-if="model.id">{{ model.projectname2 + '-' }}</b>
              <b>项目立项变更</b>
            </p>
            <p class="light">
              <span>项目经理：{{ model.projectmanager2 ? model.projectmanager2 + '【' + model.projectmanagercode2 + '】' : user.name + '【' + user.code + '】' }}</span>
              <span v-if="model.createon">创建时间：{{ formatDate(model.createon) }}</span>
            </p>
          </div>
        </div>
        <div class="toolbar">
          <el-button type="danger" size="small" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
        </div>
      </div>
      <div class="mpm-project-nav" :style="{ height: mainHeight + 'px' }">
        <ul class="nav-list">
          <template v-for="item in navList">
            <li :key="item.code" :class="item.on ? 'on' : ''" @click="clickNav(item.code)" style="cursor: pointer;clear: both">
              <span style="float: left;width: 150px">{{ item.name }}</span>
              <span style="float: left;">
                <i v-if="item.count > 0">{{ item.count }}</i>
                <label v-if="item.flag">{{ item.flag }}</label>
              </span>
            </li>
          </template>
        </ul>
      </div>
      <div class="mpm-project-main" :style="{ height: mainHeight + 'px' }">
        <el-scrollbar class="mpm-project-main-container" id="mpmMainContainer">
          <div style="padding:0 10px">
            <el-form v-if="extraParam === 'PMO'" class="tl-form" ref="pmodealform" :model="model" :rules="rules" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="审批类型" prop="approvaltype2" :rules="rules.rulesForInfo">
                    <el-select v-model="model.approvaltype2" filterable clearable>
                      <el-option v-for="item in codeModel.mpmPmoChangeTypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目类型" prop="pmoprojecttype2" :rules="rules.validateRequire">
                    <el-select v-model="model.pmoprojecttype2" filterable>
                      <el-option v-for="item in codeModel.pmoprojecttypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <!-- CEO审批显示 -->
            <el-form v-if="extraParam === 'CEO'" class="tl-form" style="margin-top: 20px" ref="ceodealform" :model="model" :rules="rules" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="审批类型" prop="ceoapprovaltype2" :rules="rules.validateRequire">
                    <el-select
                      v-model="model.ceoapprovaltype2"
                      filterable
                      clearable
                      @change="
                        (val) => {
                          openMeetDialog(val, 'meetEdit')
                        }
                      "
                    >
                      <el-option v-for="item in codeModel.mpmCeoApprovalTypeList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <div v-if="model.ceoapprovaltype2 === '1'">
                <a id="ceomeetresolution" class="step-position">&nbsp;</a>
                <div class="tl-form-line-title">
                  会议决议记录
                </div>
                <label style="font-size: 10px; color: red;margin-left: 27px;">发布会议并上传会议纪要后才能通过审批，可以选择会议秘书代上传会议纪要</label>
                <meet-list-comp ref="meetlist" :disableEditSubmit="disableEditSubmit" :sourcetype="'changeMeetResolution'" :projectid="model.id"></meet-list-comp>
              </div>
            </el-form>
            <!-- 林总邀请和林总审批显示 -->
            <el-form v-if="extraParam === 'LIN' || extraParam === 'LINInvite'" class="tl-form" ref="lindealform" :model="model" :rules="rules" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目级别" prop="projectlevel2" :rules="rules.rulesForInfo">
                    <el-select v-model="model.projectlevel2" filterable clearable>
                      <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code" :disabled="item.code === '3'" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <!-- 林总邀请审批显示 -->
            <el-form v-if="extraParam === 'LINInvite'" class="tl-form" ref="lininvitedealform" :model="model" :rules="rules" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="邀请决策" prop="invitedecisionusername2">
                    <el-input v-model="model.invitedecisionusername2" class="tl-ref-selector" disabled>
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectResourcePoolDialog"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <el-row v-if="extraParam === 'CEO' || extraParam === 'LIN' || extraParam === 'LINInvite'">
              <el-col :span="24">
                <el-divider content-position="center"><span>【以下信息为只读信息】</span></el-divider>
              </el-col>
            </el-row>
            <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit || disableSave">
              <a id="basic" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                立项信息
              </div>
              <el-row style="margin-left:1px">
                <el-col :span="24">
                  <el-form-item label="变更内容" prop="changecontent" :rules="rules.rulesForInfo">
                    <el-input v-model="model.changecontent" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" show-word-limit maxlength="1000" style="width:100%"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="margin-left:1px">
                <el-col :span="24">
                  <el-form-item label="变更原因" prop="changereason" :rules="rules.rulesForInfo">
                    <el-input v-model="model.changereason" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" show-word-limit maxlength="1000" style="width:100%"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目来源" prop="projectsource2">
                    <el-select v-model="model.projectsource2" @change="changeSource" filterable clearable>
                      <el-option v-for="item in codeModel.projectSourceList" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="leadOrChanceLabel" prop="chanceclue2">
                    <el-input v-model="model.chanceclue2" disabled class="tl-ref-selector">
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openChanceclueDialog" v-if="!disableSave"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目编号" prop="projectcode2">
                    <el-input v-model="model.projectcode2" :disabled="true" placeholder="系统自动生成"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目经理" prop="projectmanagercode2" :rules="rules.rulesForInfo">
                    <tl-ref-user v-model="model.projectmanagercode2" :initDisplayData.sync="model.projectmanager2" dataType="code" :singleSelect="true" :disabled="disableEditSubmit || disableSave"> </tl-ref-user>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目名称" prop="projectname2" :rules="rules.rulesForInfo">
                    <el-input v-model="model.projectname2"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目级别" prop="projectlevel2" :rules="rules.rulesForInfo">
                    <el-row type="flex">
                      <el-select v-model="model.projectlevel2" filterable clearable class="levelSelect" :disabled="model.projectlevel2 !== '' && model.projectlevel2 !== undefined && model.projectlevel2 !== null">
                        <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code" :disabled="item.code === '3'" />
                      </el-select>
                      <el-button type="primary" icon="el-icon-edit-outline" class="levelButton" @click="openChangeLevelDialog" v-if="model.projectlevel2"></el-button>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="客户名称" prop="clientname2">
                    <el-input v-model="model.clientname2" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="客户部门" prop="clientdept2">
                    <el-input v-model="model.clientdept2" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="可参与金额" prop="participatemoney2">
                    <!-- <el-form-item label="可参与金额" prop="participatemoney2" :rules="model.projectsource2 === '1' ? [] : rules.rulesForInfo"> -->
                    <el-input-number v-model="model.participatemoney2" disabled controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber"></el-input-number><span class="unitSpan">万元</span>
                    <!-- <el-input-number v-model="model.participatemoney2" :disabled="midChangePoint && model.projectsource2 !== '1'" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber"></el-input-number><span class="unitSpan">万元</span> -->
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="采购模式" prop="purchasepattern2" :rules="rules.rulesForInfo">
                    <el-select v-model="model.purchasepattern2" filterable clearable>
                      <el-option v-for="item in codeModel.MpmPurchasePatternList" :key="item.code" :label="item.name" :value="item.code" :disabled="item.code === '3'" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="计划开始日期" prop="planstartdate2" :rules="rules.rulesForInfo">
                    <el-date-picker v-model="model.planstartdate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" @change="planStart"> </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="计划结束日期" prop="planenddate2" :rules="rules.rulesForInfo">
                    <el-date-picker v-model="model.planenddate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" @change="planEnd"> </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="需求上报时间" prop="demandbegindate2" :rules="model.purchasepattern2 === '11' || model.purchasepattern2 === '13' ? rules.validateRequire : []">
                    <el-date-picker v-model="model.demandbegindate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="需求截止时间" prop="demandenddate2" :rules="model.purchasepattern2 === '11' || model.purchasepattern2 === '13' ? rules.validateRequire : []">
                    <el-date-picker v-model="model.demandenddate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd"></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="创建部门" prop="deptname" :rules="rules.rulesForInfo">
                    <tl-ref-dept v-model="model.deptname" :initDisplayData.sync="model.deptname" dataType="code" nameType="fullname" @confirm="onSelectDept" :singleSelect="true" :externalQueryParam="{ qry_enabled: 1 }" :disabled="disableEditSubmit || disableSave"> </tl-ref-dept>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="12">
                  <el-form-item label="项目周期" prop="bidcycle2">
                    <el-input v-model="model.bidcycle2" class="unitInput" :disabled="true" placeholder="系统自动计算"
                      ><template #append
                        >天</template
                      ></el-input
                    >
                  </el-form-item>
                </el-col> -->
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="区域" prop="deptname1" :rules="rules.validateRequire">
                    <el-cascader style="width:100%" :options="provinceCityList" :props="{ checkStrictly: true }" v-model="deptname" filterable @change="changeDeptname" clearable> </el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="Sponsor" prop="sponsorcode2" :rules="model.projectlevel2 === '0' || model.projectlevel2 === '1' ? rules.rulesForInfo : []">
                    <tl-ref-user v-model="model.sponsorcode2" :initDisplayData.sync="model.sponsor2" dataType="code" :singleSelect="true" :disabled="disableEditSubmit || disableSave"> </tl-ref-user>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="Owner" prop="ownercode2" :rules="model.projectlevel2 === '0' || model.projectlevel2 === '1' ? rules.rulesForInfo : []">
                    <tl-ref-user v-model="model.ownercode2" :initDisplayData.sync="model.owner2" dataType="code" :singleSelect="true" :disabled="disableEditSubmit || disableSave"> </tl-ref-user>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="决策组人员" prop="decisionusername2" :rules="rules.rulesForInfo">
                    <el-input v-model="model.decisionusername2" class="tl-ref-selector" disabled>
                      <el-button slot="append" type="primary" icon="el-icon-search" @click="openMpmProjectResourcePoolDialog" v-if="!disableSave"></el-button>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row v-if="model.changelevelreason2">
                <el-col :span="24">
                  <el-form-item label="项目级别调整原因" prop="changelevelreason2" :rules="rules.rulesForInfo">
                    <el-input v-model="model.changelevelreason2" type="textarea" :rows="4" maxlength="1000" show-word-limit> </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="招标批次" prop="bidinfo2" :rules="bidDateTime ? rules.validateRequire : []">
                    <el-input v-model="model.bidinfo2" placeholder="请填写批次全称，如国网**省电力公司**年第**次**招标"> </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="挂网日期" prop="bidbegindate2" :rules="bidDateTime ? rules.validateRequire : []">
                    <el-date-picker v-model="model.bidbegindate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" @change="bidbegindate"> </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="开标日期" prop="bidenddate2" :rules="bidDateTime ? rules.validateRequire : []">
                    <el-date-picker v-model="model.bidenddate2" type="date" placeholder="例：2021-01-01" value-format="yyyy-MM-dd" @change="bidenddate"> </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- <tl-project-bid-date-history ref="projectBidDate" :projectid="model.id" :planstartdate="model.planstartdate2" :planenddate="model.planenddate2" :biddatetime="bidDateTime" :forProjectChange="true" :projectIdForBidDate="model.projectIdForBidDate"></tl-project-bid-date-history> -->
              <div v-if="model.ceoapprovaltype2 === '1' && extraParam !== 'CEO'">
                <a id="meetresolution" class="step-position">&nbsp;</a>
                <div class="tl-form-line-title">
                  会议决议记录
                </div>
                <meet-list-comp ref="meetlist" :disableEditSubmit="disableEditSubmit || extraParam !== 'CEO'" :sourcetype="'changeMeetResolution'" :projectid="model.id"></meet-list-comp>
              </div>
              <a id="product" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                涉及产品范围
              </div>
              <el-row v-if="model.productlist && model.productlist.length > 0 && Array.isArray(model.productlist)">
                <el-col>
                  <el-divider content-position="center"><span style="font-size:16px">【内部产品】</span></el-divider>
                </el-col>
                <el-row v-for="(item, index) in model.productlist" :key="index">
                  <el-col :span="8">
                    <el-button type="text" @click="deleteProductRange(index)" size="medium" v-show="!(disableEditSubmit || disableSave)" style="float: left;padding-top: 6px"><i class="el-icon-remove-outline"></i>删除</el-button>
                    <el-form-item label="产品线/事业部" label-width="100px" style="margin-left: 50px">
                      <el-select v-model="item.productlinecode" :disabled="true">
                        <el-option v-for="item in codeModel.productlineList" :key="item.code" :label="item.name" :value="item.code" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="产品类别" label-width="100px" style="margin-left: 50px">
                      <el-select v-model="item.productcode" :disabled="true" v-if="model.projectsource2 === '1'">
                        <el-option v-for="item in codeModel.productcatalog1List" :key="item.code" :label="item.name" :value="item.code" />
                      </el-select>
                      <el-select v-model="item.productcode" :disabled="true" v-if="model.projectsource2 === '2'">
                        <el-option v-for="item in codeModel.productcatalog2List" :key="item.code" :label="item.name" :value="item.code" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="金额" :prop="'productlist.' + index + '.fund'" :rules="rules.rulesForFundInfo"> <el-input-number v-model="item.fund" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber"></el-input-number><span class="unitSpan">万元</span> </el-form-item>
                  </el-col>
                </el-row>
              </el-row>
              <el-row v-if="model.productoutlist && model.productoutlist.length > 0 && Array.isArray(model.productoutlist)">
                <el-col>
                  <el-divider content-position="center"><span style="font-size:16px">【外部产品】</span></el-divider>
                </el-col>
                <el-row v-for="(item, index) in model.productoutlist" :key="index">
                  <el-col :span="12">
                    <el-button type="text" @click="deleteOutProductRange(index)" size="medium" v-show="!(disableEditSubmit || disableSave)" style="float: left;padding-top: 6px"><i class="el-icon-remove-outline"></i>删除</el-button>
                    <el-form-item label="产品类别" label-width="100px" style="margin-left: 50px">
                      <el-input v-model="item.productname" disabled class="tl-ref-selector">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="金额" :prop="'productoutlist.' + index + '.fund'" :rules="rules.rulesForFundInfo"> <el-input-number v-model="item.fund" controls-position="right" :step="1" :min="0" :precision="2" class="unitInputNumber"></el-input-number><span class="unitSpan">万元</span> </el-form-item>
                  </el-col>
                </el-row>
              </el-row>
              <a id="background" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                项目背景
              </div>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="项目背景" prop="background2">
                    <el-input v-model="model.background2" type="textarea" :rows="4" maxlength="1000" show-word-limit> </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="项目目标" prop="target2">
                    <el-input v-model="model.target2" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="总体策划" prop="summary2">
                    <el-input v-model="model.summary2" type="textarea" :rows="4" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <a id="customer" class="step-position">&nbsp;</a>
              <!-- <div class="tl-form-line-title">
                客户信息
              </div>
              <el-row v-for="item in model.customerlist" :key="item.clientcode + item.clientname">
                <el-col :span="12">
                  <el-form-item label="客户名称">
                    <el-input v-model="item.clientname" disabled></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="客户部门">
                    <el-input v-model="item.clientdept" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="客户需求分析" prop="clientdemand2" :rules="rules.rulesForCustomeryInfo">
                    <el-input v-model="model.clientdemand2" type="textarea" :rows="6" maxlength="1000" show-word-limit> </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <tl-project-customer-decision ref="projectCustomerDecision" :projectid="mpmprojectid"></tl-project-customer-decision>
              <a id="competitor" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                竞争对手
              </div>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="主要竞争对手" prop="competitor2" :rules="rules.rulesForCompetitorInfo">
                    <el-input v-model="model.competitor2" type="textarea" :rows="8" maxlength="1000" show-word-limit> </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="SWOT分析" prop="swot2" :rules="rules.rulesForCompetitorInfo">
                    <el-input v-model="model.swot2" type="textarea" :rows="8" maxlength="1000" show-word-limit></el-input>
                  </el-form-item>
                </el-col>
              </el-row> -->
              <a id="apply" class="step-position">&nbsp;</a>
              <div class="tl-form-line-title">
                申请信息
              </div>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请人姓名" prop="username" :rules="rules.rulesForInfo">
                    <el-input v-model="model.username" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请人工号" prop="usercode">
                    <el-input v-model="model.usercode" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申请人部门" prop="applydeptname">
                    <el-input v-model="model.applydeptname" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申请人公司" prop="applyorgname">
                    <el-input v-model="model.applyorgname" :disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer" style="float: right; margin-top: 10px">
              <el-button @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave" icon="el-icon-document-checked" type="primary">保存</el-button>
              <el-button @click="doSubmitDelete(id)" :loading="saveLoading" v-if="!disableEditSubmit && id !== '' && id > 0" :disabled="model.state === 1 || model.state === 9" icon="el-icon-document-delete" type="primary">删除</el-button>
              <el-button @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval" type="primary"> <svg-icon icon-class="send" />提交审批 </el-button>
              <el-button @click="$refs.history.visible = true" :disabled="disableApprovalHistory" type="primary"> <svg-icon icon-class="list" />审批历史 </el-button>
              <el-button @click="doDelApproval" v-if="!disableEditSubmit" :disabled="disableDelApproval" type="primary"> <svg-icon icon-class="undo" />取消审批 </el-button>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <tl-approval-history ref="history" sourceType="MpmProjectChange" :sourceId="model.id" />
    <tlmpmProject-resource-pool-ref ref="mpmProjectResourcePoolRef" @confirm="getMpmProjectResourceData" :fieldKey="'usercode'" :fieldValue="'username'" :externalSelectedRowKeys="extraParam === 'LINInvite' ? model.invitedecisionusercode2 : model.decisionusercode2" :isSingleSelect="false" :externalQueryParam="externalDQueryParamForPool" :initDisplayData="extraParam === 'LINInvite' ? model.invitedecisionusername2 : model.decisionusername2">> </tlmpmProject-resource-pool-ref>
    <tlchange-ref ref="changeRef" :leadOrChanceLabel="leadOrChanceLabel" @confirm="getChanceclueData" :usercode="model.projectmanagercode2 || user.code" :externalQueryParam="{ projectsource: model.projectsource2 }" :chanceclue2="model.chanceclue2" :isSingleSelect="true" :fieldKey="rowKeyStr" :origincode="model.chanceclue2"> </tlchange-ref>
    <tlChangeLevel-ref ref="changeLevelRef" @confirm="confirmChangeLevel"></tlChangeLevel-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */

import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
import { mixin_page_fields_custom } from '@misui/mixins/mixin_page_fields_custom'
/** 子组件 */
import { validateNull } from '@tapui/utils/validate'
import tlmpmProjectResourcePoolRef from '@/views/mpm/mpmProjectResourcePool/refList'
import tlchangeRef from '@/views/mpm/mpmProject/refListChange'
import tlChangeLevelRef from '../mpmProject/changeLevelCompent'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
import meetListComp from '../../../components/meet/meetListComp'
// import tlProjectBidDateHistory from '@/views/mpm/mpmProjectBidDateHistory/edit'
import tlProjectCustomerDecision from '@/views/mpm/mpmProjectCustomerDecision/edit'

/** 工具类 */
import { formatDate } from '@tapui/utils/date'
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit, mixin_page_fields_custom],
  components: {
    tlmpmProjectResourcePoolRef,
    tlchangeRef,
    tlChangeLevelRef,
    meetListComp,
    tlProjectCustomerDecision
  },
  data() {
    var validateForTab = (rule, value, callback) => {
      if (!value) {
        this.tabName = rule.tabname
        return callback(new Error('请输入内容'))
      } else {
        return callback()
      }
    }
    var validateForFund = (rule, value, callback) => {
      if (!value) {
        this.tabName = rule.tabname
        return callback(new Error('金额必填且不能为0！'))
      } else {
        return callback()
      }
    }
    return {
      moduleTitle: '项目立项变更',
      urlPrefix: '/mpm/projectChange/',
      url: {
        // 额外的url
        queryOrgByDeptId: '/mpm/project/queryOrgByDeptId',
        list: '/cbo/approvalNodeIns/list',
        delete: '/mpm/projectChange/delete',
        projectChange: 'project/change/insert',
        changeList: '/mpm/project/changeList',
        getProvinceCityList: '/mpm/projectpolymerization/getProvinceCityList',
        queryMpmProjectid: 'mpm/project/queryMpmProjectid',
        judgeDecisionUser: '/mpm/project/judgeDecisionUser',
        queryPMoProjectType: 'mpm/project/list'
      },
      tabName: 'projectbasicinfo',
      sorterInfo: {
        // 排序参数
        sidx: 'id',
        sord: 'desc'
      },
      midChangePoint: true,
      attactives: ['1'],
      datas: [],
      pageInfo: {
        // 分页参数
        currentPage: 1, // 当前页面
        pageSize: 10, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      rowKeyStr: 'CODE',
      loading: false,
      visible: false,
      listMode: true,
      projectmodel: {},
      externalMQueryParamForPool: {},
      externalDQueryParamForPool: {},
      // 项目立项规则校验重写
      addRules: {
        // 基本信息TAB表单校验
        rulesForInfo: [
          {
            validator: validateForTab,
            tabname: 'projectbasicinfo',
            trigger: 'change'
          },
          { required: 'true', message: '请输入内容', trigger: 'change' }
        ],
        // 案例概述TAB表单验证
        rulesForCustomeryInfo: [
          {
            validator: validateForTab,
            tabname: 'projectcustomerinfo',
            trigger: 'change'
          },
          { required: 'true', message: '请输入内容', trigger: 'change' }
        ],
        rulesForCompetitorInfo: [
          {
            validator: validateForTab,
            tabname: 'projectcompetitorinfo',
            trigger: 'change'
          },
          { required: 'true', message: '请输入内容', trigger: 'change' }
        ],
        rulesForFundInfo: [{ validator: validateForFund, tabname: 'projectproductinfo', trigger: 'blur' }, { required: 'true', message: '请输入内容', trigger: 'change' }]
      },
      // CEO信息
      tempdecisionusercode: '',
      tempdecisionusername: '',
      mainHeight: 1000,
      mainScrollElement: null,
      navList: [],
      constNavList: [{ name: '立项信息', on: true, code: 'basic' }, { name: '涉及产品范围', on: false, code: 'product' }, { name: '项目背景', on: false, code: 'background' }, { name: '申请信息', on: false, code: 'apply' }, { name: '审批历史', on: false, code: 'history' }],
      // 审批节点配置的额外参数
      extraParam: '',
      // 判断是否是审批组件调用
      fromApproval: '',
      oldprojectlevel: '',
      // 项目等级，例：网级、省级等
      maxLevel: -1,
      deptname: [],
      provinceCityList: [],
      mpmprojectid: 0,
      dispLevelArr: ['A', 'B', 'C', 'D'],
      // 内部产品金额之和
      productMoneyIn: 0,
      // 外部产品金额之和
      productMoneyOut: 0
    }
  },
  props: {
    // 当前元素展示方式。默认为dialog，可选div/el-drawer
    render: {
      default: 'el-drawer',
      type: String
    }
  },
  watch: {
    // 可参与金额和产品内金额之和保持一致
    'model.productlist': {
      handler(newVal, oldVal) {
        if (!validateNull(newVal) && newVal.length > 0 && Array.isArray(newVal)) {
          let productMoneyTotle = 0
          newVal.map((item) => {
            productMoneyTotle += item.fund
          })
          this.productMoneyIn = productMoneyTotle
          this.model.participatemoney2 = this.productMoneyIn + this.productMoneyOut
        }
      },
      deep: true
    },
    // 可参与金额和产品内金额之和保持一致
    'model.productoutlist': {
      handler(newVal, oldVal) {
        if (!validateNull(newVal) && newVal.length > 0 && Array.isArray(newVal)) {
          let productMoneyTotle = 0
          newVal.map((item) => {
            productMoneyTotle += item.fund
          })
          this.productMoneyOut = productMoneyTotle
          this.model.participatemoney2 = this.productMoneyIn + this.productMoneyOut
        }
      },
      deep: true
    },
    'model.projectlevel2'(newLevel, oldLevel) {
      if (this.user.code !== '0070') {
        if ((newLevel === '0' || newLevel === '1') && (oldLevel === '2' || oldLevel === '3')) {
          let tempdecisionusercode = this.tempdecisionusercode
          let tempdecisionusername = this.tempdecisionusername
          if (this.model.decisionusercode2) {
            let decisionusercodeArr = this.model.decisionusercode2.split(',')
            let decisionusernameArr = this.model.decisionusername2.split(',')
            let tempdecisionusercodeArr = tempdecisionusercode.split(',')
            let tempdecisionusernameArr = tempdecisionusername.split(',')
            // 从CD级切换到AB级时，如果原本CD级的决策组人员有林总、省总，需要取差集(去重)
            if (this.model.decisionusercode2.indexOf(tempdecisionusercodeArr[1]) > 0 || this.model.decisionusercode2.indexOf(tempdecisionusercodeArr[2]) > 0) {
              let decisionusercodeArrNew = decisionusercodeArr.filter((v) => !tempdecisionusercodeArr.find((item) => item === v))
              let decisionusernameArrNew = decisionusernameArr.filter((v) => !tempdecisionusernameArr.find((item) => item === v))
              let resultcodes = ''
              let resultnames = ''
              let code = []
              let name = []
              for (let i = 1; i < decisionusercodeArrNew.length - 1; i++) {
                code.push(decisionusercodeArrNew[i])
              }
              for (let i = 0; i < decisionusernameArrNew.length; i++) {
                name.push(decisionusernameArrNew[i])
              }
              let codes = code.join(',')
              resultcodes = codes ? ',' + codes + ',' : ''
              let names = name.join(',')
              resultnames = names ? ',' + names : ''
              tempdecisionusercode = tempdecisionusercode + resultcodes.substring(1)
              tempdecisionusername = tempdecisionusername + resultnames
              this.$set(this.model, 'decisionusercode2', tempdecisionusercode)
              this.$set(this.model, 'decisionusername2', tempdecisionusername)
            } else {
              tempdecisionusercode = tempdecisionusercode + this.model.decisionusercode2.substring(1)
              tempdecisionusername = tempdecisionusername + ',' + this.model.decisionusername2
              this.$set(this.model, 'decisionusercode2', tempdecisionusercode)
              this.$set(this.model, 'decisionusername2', tempdecisionusername)
            }
          } else if (!this.model.decisionusercode2) {
            this.$set(this.model, 'decisionusercode2', tempdecisionusercode)
            this.$set(this.model, 'decisionusername2', tempdecisionusername)
          }
          // 判断切换后的人员是否在当前等级下可以被选中，如果在参照中无法被选中，将此人员过滤掉（即人员等级为CD级）
          this.judgeDecisionUser(newLevel)
        } else if ((newLevel === '2' || newLevel === '3') && (oldLevel === '0' || oldLevel === '1')) {
          // 由AB切换到CD级
          let decisionusercodeArr = this.model.decisionusercode2.split(',')
          let decisionusernameArr = this.model.decisionusername2.split(',')
          let tempdecisionusercodeArr = this.tempdecisionusercode.split(',')
          let tempdecisionusernameArr = this.tempdecisionusername.split(',')
          if (this.model.decisionusercode2.indexOf(tempdecisionusercodeArr[1]) > 0 || this.model.decisionusercode2.indexOf(tempdecisionusercodeArr[2]) > 0) {
            // 取差集
            let decisionusercodeArrNew = decisionusercodeArr.filter((v) => !tempdecisionusercodeArr.find((item) => item === v))
            let decisionusernameArrNew = decisionusernameArr.filter((v) => !tempdecisionusernameArr.find((item) => item === v))
            let resultcodes = ''
            let resultnames = ''
            let code = []
            let name = []
            for (let i = 1; i < decisionusercodeArrNew.length - 1; i++) {
              code.push(decisionusercodeArrNew[i])
            }
            for (let i = 0; i < decisionusernameArrNew.length; i++) {
              name.push(decisionusernameArrNew[i])
            }
            let codes = code.join(',')
            resultcodes = codes ? ',' + codes + ',' : ''
            resultnames = name.join(',')
            this.$set(this.model, 'decisionusercode2', resultcodes)
            this.$set(this.model, 'decisionusername2', resultnames)
          }
          // 判断切换后的人员是否在当前等级下可以被选中，如果在参照中无法被选中，将此人员过滤掉（即人员等级为CD级）
          this.judgeDecisionUser(newLevel)
        }
      }
    }
  },
  computed: {
    leadOrChanceLabel() {
      if (this.model.projectsource2 && this.codeModel.projectSourceList) {
        let result = this.codeModel.projectSourceList.find((item) => item.code === this.model.projectsource2).name
        return result
      } else {
        return '线索/机会点'
      }
    },
    historyLevel() {
      if (this.model.levelhistory2) {
        return JSON.parse(this.model.levelhistory2.replace(/\//g, '')).oldprojectlevel
      } else {
        return ''
      }
    },
    // 挂网开标日期计算属性
    bidDateTime() {
      return this.model.purchasepattern2 === '11' || this.model.purchasepattern2 === '12' || this.model.purchasepattern2 === '13'
    },
    customerNeedbidDate() {
      if (!validateNull(this.model.customerlist)) {
        let customerlist = this.model.customerlist
        for (let i in customerlist) {
          if (customerlist[i].clientcatalog === 'A' || customerlist[i].clientcatalog === 'B' || customerlist[i].clientcatalog === 'C') {
            return true
          }
        }
        return false
      } else {
        return false
      }
    }
  },
  methods: {
    beforeDoDelete(id) {
      return true
    },
    // 删除功能
    doSubmitDelete(id) {
      this.saveLoading = true
      if (!this.url.delete) {
        this.$tap.alert('请设置delete地址!', 'warning')
        this.saveLoading = false
        return
      }
      this.$tap
        .confirm('确定删除数据吗？')
        .then((_) => {
          if (!this.beforeDoDelete(id)) {
            this.saveLoading = false
            return
          }
          deleteAction(this.url.delete, { ids: id }).then((res) => {
            if (res.success) {
              this.doCancelEdit()
              this.saveLoading = false
              this.id = ''
              this.$tap.message(res.message, 'success')
            } else {
              this.saveLoading = false
              this.$tap.alert(res.message, 'warning')
            }
          })
        })
        .catch((_) => {
          this.saveLoading = false
        })
    },
    async doSubmitEdit() {
      let a = await this.beforeSubmit()
      if (!a) {
        return
      }
      if (this.isAdd) {
        this.doAdd()
      } else {
        this.doEdit()
      }
    },
    /** 执行新增提交 */
    doAdd() {
      this.saveLoading = true
      // 增加唯一单号
      this.$set(this.model, 'billuid', this.uid)
      postAction(this.url.add, this.model)
        .then((res) => {
          if (res.success) {
            this.id = res.result.id
            this.$tap.message('添加成功', 'success')
            this.queryData(res.result.id).then((_) => {
              this.loaded()
            })
            this.isAdd = false
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.saveLoading = false
        })
        .catch((err) => {
          this.saveLoading = false
        })
    },
    planStart(e) {
      if (this.model.planenddate2) {
        var a = new Date(this.model.planstartdate2).getTime()
        var b = new Date(this.model.planenddate2).getTime()
        if (a > b) {
          this.$tap.alert('开始日期不得大于结束日期。', 'warning')
          this.$set(this.model, 'planstartdate2', '')
          this.$set(this.model, 'bidcycle2', '')
          return
        } else {
          var t = b - a
          var days = Math.ceil(t / (1000 * 3600 * 24)) + 1
          this.$set(this.model, 'bidcycle2', days)
        }
      }
    },
    planEnd(e) {
      if (this.model.planstartdate2) {
        var c = new Date(this.model.planenddate2).getTime()
        var d = new Date(this.model.planstartdate2).getTime()
        if (c < d) {
          this.$tap.alert('开始日期不得大于结束日期。', 'warning')
          this.$set(this.model, 'planenddate2', '')
          this.$set(this.model, 'bidcycle2', '')
          return
        }
        var a = c - d
        var days = Math.ceil(a / (1000 * 3600 * 24)) + 1
        this.$set(this.model, 'bidcycle2', days)
        // 计划结束日期存储为选择日期的的23：59：59
        let date = new Date(c)
        let timeDate = ''
        let Y = date.getFullYear() + '-'
        let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
        let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
        let h = 23 + ':'
        let m = 59 + ':'
        let s = 59
        timeDate = Y + M + D + h + m + s
        this.$set(this.model, 'planenddate', timeDate)
      }
    },
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'changetype', '1')
        this.$set(this.model, 'chanceclue2', this.projectmodel.chanceclue)
        this.$set(this.model, 'changelevelreason2', this.projectmodel.changelevelreason)
        this.$set(this.model, 'projectcode2', this.projectmodel.projectcode)
        this.$set(this.model, 'projectname2', this.projectmodel.projectname)
        this.$set(this.model, 'participatemoney2', this.projectmodel.participatemoney)
        this.$set(this.model, 'projectlevel2', this.projectmodel.projectlevel)
        this.$set(this.model, 'originalprojectlevel', this.projectmodel.projectlevel)
        this.$set(this.model, 'projectdefaultlevel2', this.projectmodel.projectdefaultlevel)
        this.$set(this.model, 'purchasepattern2', this.projectmodel.purchasepattern)
        this.$set(this.model, 'planstartdate2', this.projectmodel.planstartdate)
        this.$set(this.model, 'planenddate2', this.projectmodel.planenddate)
        this.$set(this.model, 'deptname2', this.projectmodel.deptname)
        this.$set(this.model, 'bidcycle2', this.projectmodel.bidcycle)
        this.$set(this.model, 'bidinfo2', this.projectmodel.bidinfo)
        this.$set(this.model, 'bidbegindate2', this.projectmodel.bidbegindate)
        this.$set(this.model, 'bidenddate2', this.projectmodel.bidenddate)
        this.$set(this.model, 'projectmanager2', this.projectmodel.projectmanager)
        this.$set(this.model, 'projectmanagercode2', this.projectmodel.projectmanagercode)
        this.$set(this.model, 'sponsor2', this.projectmodel.sponsor)
        this.$set(this.model, 'sponsorcode2', this.projectmodel.sponsorcode)
        this.$set(this.model, 'owner2', this.projectmodel.owner)
        this.$set(this.model, 'ownercode2', this.projectmodel.ownercode)
        this.$set(this.model, 'decisionusername2', this.projectmodel.decisionusername)
        this.$set(this.model, 'decisionusercode2', this.projectmodel.decisionusercode)
        this.$set(this.model, 'productlist', this.projectmodel.productlist)
        this.$set(this.model, 'productoutlist', this.projectmodel.productoutlist)
        this.$set(this.model, 'background2', this.projectmodel.background)
        this.$set(this.model, 'target2', this.projectmodel.target)
        this.$set(this.model, 'summary2', this.projectmodel.summary)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'deptcode', this.projectmodel.deptcode)
        this.$set(this.model, 'applydeptname', this.dept.fullname)
        this.$set(this.model, 'applydeptcode', this.dept.code)
        this.$set(this.model, 'applyorgname', this.org.name)
        this.$set(this.model, 'clientname2', this.projectmodel.clientname)
        this.$set(this.model, 'clientdept2', this.projectmodel.clientdept)
        this.$set(this.model, 'clientsupport2', this.projectmodel.clientsupport)
        this.$set(this.model, 'clientdemand2', this.projectmodel.clientdemand)
        this.$set(this.model, 'decisionmode2', this.projectmodel.decisionmode)
        this.$set(this.model, 'competitor2', this.projectmodel.competitor)
        this.$set(this.model, 'swot2', this.projectmodel.swot)
        this.$set(this.model, 'projectsource2', this.projectmodel.projectsource)
        this.$set(this.model, 'levelhistory2', this.projectmodel.levelhistory)
        // 处理脏数据，使用newadd字段标识项目立项变更新增记录
        this.$set(this.model, 'newadd', 1)
        this.$set(this.model, 'deptcommoncode2', this.projectmodel.deptcommoncode)
        this.$set(this.model, 'customerlist', JSON.parse(JSON.stringify(this.projectmodel.customerlist)))
        this.$set(this.model, 'deptname1', this.projectmodel.deptname1)
        this.$set(this.model, 'deptname2', this.projectmodel.deptname2)
        this.$set(this.model, 'deptname3', this.projectmodel.deptname3)
        this.$set(this.model, 'demandbegindate2', this.projectmodel.demandbegindate)
        this.$set(this.model, 'demandenddate2', this.projectmodel.demandenddate)
        this.$set(this.model, 'clientlevel2', this.projectmodel.clientlevel)
        this.$set(this.model, 'pmoprojecttype2', this.projectmodel.pmoprojecttype)
        this.deptname = []
        if (this.model.deptname1) {
          this.deptname.push(this.model.deptname1)
        }
        if (this.model.deptname2) {
          this.deptname.push(this.model.deptname2)
        }
        if (this.model.deptname3) {
          this.deptname.push(this.model.deptname3)
        }
      }
    },
    bidbegindate(e) {
      if (this.model.planstartdate2 === '' || typeof this.model.planstartdate2 === 'undefined' || this.model.planenddate2 === '' || typeof this.model.planenddate2 === 'undefined') {
        this.$tap.alert('请先选择计划开始日期和计划结束日期！', 'warning')
        this.$set(this.model, 'bidbegindate2', '')
        return
      }
      var planenddate2 = new Date(this.model.planenddate2).getTime()
      var planstartdate2 = new Date(this.model.planstartdate2).getTime()
      var bidbegindate2 = new Date(this.model.bidbegindate2).getTime()
      if (bidbegindate2 < planstartdate2) {
        this.$tap.alert('挂网日期不能早于计划开始日期！', 'warning')
        this.$set(this.model, 'bidbegindate2', '')
        return
      }
      if (bidbegindate2 > planenddate2) {
        this.$tap.alert('挂网日期不能晚于计划结束日期！', 'warning')
        this.$set(this.model, 'bidbegindate2', '')
        return
      }
      if (this.model.bidenddate2) {
        var bidenddate2 = new Date(this.model.bidenddate2).getTime()
        if (bidbegindate2 > bidenddate2) {
          this.$tap.alert('挂网日期不能晚于开标日期！', 'warning')
          this.$set(this.model, 'bidbegindate2', '')
          return
        }
      }
    },
    bidenddate(e) {
      if (this.model.planstartdate2 === '' || typeof this.model.planstartdate2 === 'undefined' || this.model.planenddate2 === '' || typeof this.model.planenddate2 === 'undefined') {
        this.$tap.alert('请先选择计划开始日期和计划结束日期！', 'warning')
        this.$set(this.model, 'bidenddate2', '')
        return
      }
      var planenddate2 = new Date(this.model.planenddate2).getTime()
      var planstartdate2 = new Date(this.model.planstartdate2).getTime()
      var bidenddate2 = new Date(this.model.bidenddate2).getTime()
      if (bidenddate2 < planstartdate2) {
        this.$tap.alert('开标日期不能早于计划开始日期！', 'warning')
        this.$set(this.model, 'bidenddate2', '')
        return
      }
      if (bidenddate2 > planenddate2) {
        this.$tap.alert('开标日期不能晚于计划结束日期！', 'warning')
        this.$set(this.model, 'bidenddate2', '')
        return
      }
      if (this.model.bidbegindate2) {
        var bidbegindate2 = new Date(this.model.bidbegindate2).getTime()
        if (bidbegindate2 > bidenddate2) {
          this.$tap.alert('挂网日期不能晚于开标日期！', 'warning')
          this.$set(this.model, 'bidenddate2', '')
          return
        }
      }
    },
    // beforeApproval() {
    //   if (this.model.projectmanagercode2 === this.model.sponsorcode2 || this.model.projectmanagercode2 === this.model.ownercode2 || this.model.sponsorcode2 === this.model.ownercode2) {
    //     this.$tap.alert('项目经理、sponsor和owner不能重复，请确认！', 'warning')
    //     return false
    //   } else {
    //     return true
    //   }
    // },
    async beforeSubmit() {
      let a = await this.queryBeforeOtherChangeInfo()
      if (!a) {
        this.$tap.alert('存在编辑中未提交的变更数据，请提交后再提交变更！')
      }
      return a
    },
    async queryBeforeOtherChangeInfo() {
      let idtemp = this.id && this.id > 0 ? this.id : 0
      var param = {
        qry_projectcode: this.model.projectcode2,
        qry_newadd: 1,
        qry_state: '0,1,2',
        qry_notid: idtemp
      }
      return await getAction('/mpm/projectChange/list', param).then((res) => {
        if (res.success) {
          if (res.result.dataList.length === 0) {
            return true
          } else {
            return false
          }
        } else {
          return false
        }
      })
    },
    /** 重写提交审批，调用loaded解析产品JSON数据 */
    async doSubmitApproval() {
      if (!this.url.submit) {
        this.$tap.alert('请设置审批地址!', 'warning')
        return
      }
      let fileValidate = true
      this.$refs.form.validate((valid) => {
        if (!valid) {
          fileValidate = false
        }
      })
      if (!fileValidate) {
        return
      }
      let a = await this.beforeSubmit()
      if (!a) {
        return
      }
      if (!this.beforeApproval()) {
        return
      }
      // 提交前校验产品不能为空
      if ((!this.model.productlist || this.model.productlist.length === 0) && (!this.model.productlist || this.model.productoutlist.length === 0)) {
        this.$tap.alert('涉及产品范围不能为空，请前往线索/机会点添加产品！', 'warning')
        return
      }
      this.saveLoading = true
      this.submitLoading = true
      this.$tap
        .confirm('确定提交审批吗？提交后，单据内容不可修改！')
        .then((_) => {
          putAction(this.url.submit, this.model).then((res) => {
            if (res.success) {
              this.$tap.message(res.message, 'success')
              this.queryData(this.model.id).then((_) => {
                this.loaded()
              })
              this.afterApproval()
            } else {
              this.$tap.alert(res.message, 'warning')
            }
            this.saveLoading = false
            this.submitLoading = false
          })
        })
        .catch((_) => {
          this.saveLoading = false
          this.submitLoading = false
        })
    },
    /** 执行编辑提交 */
    doEdit() {
      this.saveLoading = true
      putAction(this.url.edit, this.model)
        .then((res) => {
          if (res.success) {
            this.$tap.message(res.message, 'success')
            this.$emit('refresh')
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterSubmit()
          this.saveLoading = false
        })
        .catch((err) => {
          this.saveLoading = false
        })
    },
    // 选择项目所属部门
    onSelectDept(selectedDepts) {
      const selectedDept = selectedDepts[0]
      const { id, code, fullname } = selectedDept
      this.$set(this.model, 'deptcode', code)
      this.$set(this.model, 'deptname', fullname)
      const param = {
        deptId: id
      }
      getAction(this.url.queryOrgByDeptId, param).then((res) => {
        if (res.success) {
          const { code: orgcode, name: orgname } = res.result
          this.$set(this.model, 'orgcode', orgcode)
          this.$set(this.model, 'orgname', orgname)
        } else {
          this.$tap.alert('已选部门关联公司信息错误，请联系系统管理员')
        }
      })
    },
    /** 抽屉组件必重写，主要为了执行resizeHandler方法、给mainScrollElement赋值，并添加监听事件，不要直接复制该方法 **/
    open() {
      this.model = {}
      this.resizeHandler()
      this.$nextTick(() => {
        this.getFieldsCustomSetting('projectpolymerization', 'el-form')
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '新增' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          let params = {
            managercode: this.user.code
          }
          getAction('mpm/projectChange/queryCeo', params).then((res) => {
            if (res.success) {
              let code = []
              let name = []
              res.result.forEach((element) => {
                code.push(element.usercode)
                name.push(element.username)
              })
              let codes = ',' + code.join(',') + ','
              let names = name.join(',')
              // 立项变更和项目立项在此处不同
              // this.$set(this.model, 'decisionusercode2', codes)
              // this.$set(this.model, 'decisionusername2', names)
              // 将CEO信息存到中间变量中
              this.tempdecisionusercode = codes
              this.tempdecisionusername = names
            }
          })
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then((_) => {
              this.assignDefaultValue()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化
            this.$set(this.model, 'enabled', 1)
            this.$set(this.model, 'sortcode', 0)
            this.assignDefaultValue()
            this.loaded()
          }
          // 获取省区地市信息
          this.getProvinceCityList()
        } else if (this.disableEditSubmit === false) {
          let params = {
            projectid: this.id
          }
          getAction('mpm/projectChange/queryCeo', params).then((res) => {
            if (res.success) {
              let code = []
              let name = []
              res.result.forEach((element) => {
                code.push(element.usercode)
                name.push(element.username)
              })
              let codes = ',' + code.join(',') + ','
              let names = name.join(',')
              // 将CEO信息存到中间变量中
              this.tempdecisionusercode = codes
              this.tempdecisionusername = names
            }
          })
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            // 编辑状态获取项目等级
            this.getMaxLevel()
            // 获取省区地市信息
            this.getProvinceCityList()
            this.loaded()
          })
        } else {
          let params = {
            projectid: this.id
          }
          getAction('mpm/projectChange/queryCeo', params).then((res) => {
            if (res.success) {
              let code = []
              let name = []
              res.result.forEach((element) => {
                code.push(element.usercode)
                name.push(element.username)
              })
              let codes = ',' + code.join(',') + ','
              let names = name.join(',')
              // 将CEO信息存到中间变量中
              this.tempdecisionusercode = codes
              this.tempdecisionusername = names
            }
          })
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then((_) => {
            // 编辑状态获取项目等级
            this.getMaxLevel()
            // 获取省区地市信息
            this.getProvinceCityList()
            this.loaded()
          })
        }
        this.mainScrollElement = document.getElementById('mpmMainContainer').getElementsByClassName('el-scrollbar__wrap')[0]
        this.onMainScroll()
      })
      this.datas = []
      this.loadData({ currentPage: 1 })
    },
    getProvinceCityList() {
      let param = {
        usercode: this.model.projectmanagercode2,
        deptcode: this.model.deptcode
      }
      getAction(this.url.getProvinceCityList, param)
        .then((res) => {
          if (res.success) {
            this.provinceCityList = res.result.provinceCityList
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    // 数据库字符串对象去特殊字符
    loaded() {
      // 挂网开标日期组件
      // this.$refs.projectBidDate.isAdd = this.isAdd
      // this.$refs.projectBidDate.disableEditSubmit = this.disableEditSubmit
      // this.$refs.projectBidDate.disableSave = this.disableSave
      // this.$refs.projectBidDate.open()
      // this.$set(this.model, 'projectBidDate', this.$refs.projectBidDate.model.projectDateList)
      // 挂网招标日期项目id
      this.$set(this.model, 'projectIdForBidDate', this.projectmodel.id)
      getAction(this.url.queryMpmProjectid, { projectcode: this.model.projectcode2 }).then((res) => {
        if (res.success) {
          this.mpmprojectid = res.result.id
          // this.$refs.projectCustomerDecision.isAdd = false
          // this.$refs.projectCustomerDecision.disableEditSubmit = true
          // this.$refs.projectCustomerDecision.disableSave = true
          // this.$refs.projectCustomerDecision.open()
        }
      })
      // 给midChangePoint赋初始值
      if (this.model.chanceclue2) {
        this.midChangePoint = this.model.chanceclue2.split(',') <= 1
      }
      if (!this.isAdd) {
        this.deptname = []
        if (this.model.deptname1) {
          this.deptname.push(this.model.deptname1)
        }
        if (this.model.deptname2) {
          this.deptname.push(this.model.deptname2)
        }
        if (this.model.deptname3) {
          this.deptname.push(this.model.deptname3)
        }
        // navList赋值
        this.setNavListValue()
        this.$refs.form.clearValidate()
      }
    },
    setNavListValue() {
      this.navList = []
      this.constNavList.forEach((item) => this.navList.push(item))
      if (this.extraParam !== 'CEO' && this.model.ceoapprovaltype2 === '1') {
        this.navList.splice(1, 0, { name: '会议决策记录', on: false, code: 'meetresolution' })
      }
    },
    /** 加载审批历史列表数据 */
    loadData(paramMap) {
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      // 查询条件
      this.sorterInfo.sidx = 'approvaldate'
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    /** 执行查询 */
    doQuery() {
      this.loadData({ currentPage: 1 })
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      return filterObjectNull(param)
    },
    /** 表格列排序 */
    doSortChange(columnInfo, prop, order) {
      if (columnInfo.column === null) {
        return
      }
      // 不排序
      if (validateNull(columnInfo.order)) {
        this.loadData({})
        return
      }
      // 升序或者降序排序
      if (columnInfo.column.sortBy) {
        this.sorterInfo.sidx = columnInfo.column.sortBy
      } else {
        this.sorterInfo.sidx = columnInfo.prop
      }
      this.sorterInfo.sord = columnInfo.order.replace('ending', '')
      this.loadData({})
    },
    /** 每页大小改变 */
    doChangeSize(val) {
      if (this.pageInfo.pageSize !== val) {
        this.pageInfo.pageSize = val
        this.pageInfo.currentPage = 1
        this.loadData({})
      }
    },
    /** 页面跳转 */
    doChangeIndex(val) {
      if (this.pageInfo.currentPage !== val) {
        this.pageInfo.currentPage = val
        this.loadData({})
      }
    },
    drawDiagram(map) {
      /* eslint-disable*/
      $('#history-myflow').html('')
      let restore = map.strdiagram
      restore = restore.replace(/'/g, '"')
      if (restore !== '') {
        restore = JSON.parse(restore)
      }
      let history = map.strhistory
      history = history.replace(/'/g, '"')
      history = history.replace(/activeRects/g, '"activeRects"')
      history = history.replace(/historyRects/g, '"historyRects"')
      history = history.replace(/rects/g, '"rects"')
      history = history.replace(/paths/g, '"paths"')
      history = history.replace(/code/g, '"code"')
      if (history !== '') {
        history = JSON.parse(history)
      }
      $('#history-myflow').myflow(
        $.extend(false, {
          basePath: '',
          restore: restore,
          editable: false,
          ...history
        })
      )
    },
    // 项目级别变更后，清空项目经理和决策组--2-7todo 暂时取消
    clear() {
      if (this.model.projectmanagercode || this.model.decisionusercode) {
        this.$set(this.model, 'projectmanagercode', '')
        this.$set(this.model, 'projectmanager', '')
        this.$set(this.model, 'decisionusercode', '')
        this.$set(this.model, 'decisionusername', '')
      }
    },
    /** 打开决策组成员参照 */
    openMpmProjectResourcePoolDialog() {
      const { projectlevel2, projecttype2 } = this.model
      if (!projectlevel2) {
        this.$tap.alert('请先选择项目级别！', 'warning')
        this.$refs.mpmProjectResourcePoolRef.visible = false
      } else {
        this.externalDQueryParamForPool = {
          projectlevel: projectlevel2,
          projecttype: projecttype2
        }
        this.$refs.mpmProjectResourcePoolRef.visible = true
      }
    },
    /** 获取决策组成员参照数据 */
    getMpmProjectResourceData(selectionRow, selectKey, selectionValue) {
      // 如果是林总邀请审批
      if (this.extraParam === 'LINInvite') {
        let resultcodes = ''
        let resultnames = ''
        if (Array.isArray(selectionRow)) {
          if (selectionRow.length > 0) {
            let code = []
            let name = []
            selectionRow.forEach((element) => {
              code.push(element.usercode)
              name.push(element.username)
            })
            resultcodes += ',' + code.join(',') + ','
            resultnames += name.join(',')
          }
        } else {
          if (selectionRow.usercode) {
            resultcodes += ',' + selectionRow.usercode + ','
            resultnames += selectionRow.username
          }
        }
        this.$set(this.model, 'invitedecisionusercode2', resultcodes)
        this.$set(this.model, 'invitedecisionusername2', resultnames)
      } else {
        if (this.model.projectlevel2 === '0' || this.model.projectlevel2 === '1') {
          // 将CEO数据分割为数组
          let tempdecisionusercodeArr = this.tempdecisionusercode.split(',')
          let resultcodes = this.tempdecisionusercode
          let resultnames = this.tempdecisionusername
          if (Array.isArray(selectionRow)) {
            if (selectionRow.length > 0) {
              let code = []
              let name = []
              selectionRow.forEach((element) => {
                // 移除选择的人员中的CEO数据
                if (tempdecisionusercodeArr.indexOf(element.usercode) < 0) {
                  code.push(element.usercode)
                  name.push(element.username)
                }
              })
              if (code.length > 0 && name.length > 0) {
                resultcodes += code.join(',') + ','
                resultnames += ',' + name.join(',')
              }
            }
          } else {
            if (selectionRow.usercode && tempdecisionusercodeArr.indexOf(selectionRow.usercode) < 0) {
              resultcodes += selectionRow.usercode + ','
              resultnames += ',' + selectionRow.username
            }
          }
          this.$set(this.model, 'decisionusercode2', resultcodes)
          this.$set(this.model, 'decisionusername2', resultnames)
        } else {
          // 如果是CD级项目
          let resultcodes = ''
          let resultnames = ''
          if (Array.isArray(selectionRow)) {
            if (selectionRow.length > 0) {
              let code = []
              let name = []
              selectionRow.forEach((element) => {
                code.push(element.usercode)
                name.push(element.username)
              })
              let codes = code.join(',')
              resultcodes = codes ? ',' + codes + ',' : ''
              resultnames = name.join(',')
            }
          } else {
            resultcodes = ',' + selectionRow.usercode + ','
            resultnames = selectionRow.username
          }
          this.$set(this.model, 'decisionusercode2', resultcodes)
          this.$set(this.model, 'decisionusername2', resultnames)
        }
      }
    },
    /** 打开机会点参照 */
    openChanceclueDialog() {
      if (!this.model.projectsource2) {
        this.$tap.alert('请先选择项目来源！', 'warning')
      } else {
        this.$refs.changeRef.visible = true
      }
    },
    /** 获取机会点参照数据 */
    getChanceclueData(selectionRow, selectKey, selectionValue) {
      var participatemoney2 = 0
      //项目名称，可参与金额须手填
      this.midChangePoint = false
      var chanceclue = ''
      var clientlevel = ''
      // 先清空项目经理
      this.$set(this.model, 'projectmanager', '')
      this.$set(this.model, 'projectmanagercode', '')
      // 清空客户数组
      this.model.customerlist = []
      // 公司和非公司产品
      var proType = []
      var proOutType = []
      //循环取值
      selectionRow.forEach((item, index) => {
        this.$set(this.model, 'projectname2', item.PROJECT_NAME)
        this.$set(this.model, 'projectmanager2', item.GARDENER_NAME)
        this.$set(this.model, 'projectmanagercode2', item.GARDENER_CODE)
        this.$set(this.model, 'deptname', item.DEPT_COMMON_CODE_1NAME)
        //从机会点获取到的creator_dept_code 作为创建部门编码(deptcode)，根据创建部门编码，走审批
        this.$set(this.model, 'deptcode2', item.CREATOR_DEPT_CODE)
        this.$set(this.model, 'participatemoney2', item.OUR_PROCDUCT_FUND)
        this.$set(this.model, 'clientname2', item.CLIENT_NAME)
        this.$set(this.model, 'clientdept2', item.CLIENT_DEPT_NAME)
        participatemoney2 = participatemoney2 + parseFloat(item.OUR_PROCDUCT_FUND)
        this.$set(this.model, 'participatemoney2', participatemoney2)
        //填充机会点,拼接客户类型（网、省、市、县级）
        if (chanceclue.length > 0) {
          chanceclue = chanceclue + ',' + item.CODE
          clientlevel = clientlevel + ',' + item.CLIENT_LEVEL
        } else {
          chanceclue = item.CODE
          clientlevel = item.CLIENT_LEVEL
        }
        //填充涉及产品范围，获取产品类型，拼装产品金额，请求报文为json数组
        if (item.CATALOG) {
          var tempCatalog = item.CATALOG.split(',')
          var tempCatalogCode = item.CATALOGCODE.split(',')
          var tempFund = item.FUND.split(',')
          var tempProductLine = item.LINE.split(',')
          tempCatalog.forEach((element, index) => {
            let flag = false
            for (var i in proType) {
              if (proType[i].productname === element) {
                flag = true
                var tempProduct = { productlinecode: proType[i].productlinecode, productname: proType[i].productname, productcode: proType[i].productcode, fund: parseFloat(proType[i].fund + tempFund[index]) }
                proType.splice(i, 1, tempProduct)
                break
              }
            }
            if (!flag) {
              proType.push({ productlinecode: tempProductLine[index], productname: element, productcode: tempCatalogCode[index], fund: parseFloat(tempFund[index]) })
            }
          })
        }
        //填充外部产品范围，获取产品类型，拼装产品金额，请求报文为json数组
        if (item.CATALOGOUT) {
          var tempCatalogOut = item.CATALOGOUT.split(',')
          var tempFundOut = item.FUNDOUT.split(',')
          tempCatalogOut.forEach((element, index) => {
            let flagOut = false
            for (var i in proOutType) {
              if (proOutType[i].productname === element) {
                flagOut = true
                var tempProductOut = { productname: proOutType[i].productname, fund: parseFloat(proOutType[i].fund + tempFundOut[index]) }
                proOutType.splice(i, 1, tempProductOut)
                break
              }
            }
            if (!flagOut) {
              proOutType.push({ productname: element, fund: parseFloat(tempFundOut[index]) })
            }
          })
        }
        // 向客户信息数组中赋值
        if (!this.model.customerlist.find((cus) => cus.clientname === item.CLIENT_NAME)) {
          this.model.customerlist.push({
            clientname: item.CLIENT_NAME,
            clientdept: item.CLIENT_DEPT_NAME,
            clientcode: item.CLIENT_CODE,
            clientcatalog: item.CLIENT_CATALOG,
            customersourcetype: item.CUSTOMER_SOURCE_TYPE,
            sourcetype: 'MpmProjectChange'
          })
        }
      })
      this.$set(this.model, 'productlist', proType)
      this.$set(this.model, 'productoutlist', proOutType)
      this.$set(this.model, 'chanceclue2', chanceclue)
      this.$set(this.model, 'clientlevel2', clientlevel)
      let tempClientCode = ''
      let tempClientName = ''
      let tempClientSourcetype = ''
      let tempClientDept = ''
      this.model.customerlist.forEach((item, index) => {
        if (index === 0) {
          if (item.clientname !== null && item.clientname !== '') {
            tempClientName = item.clientname
          }
          tempClientCode = item.clientcode
          tempClientSourcetype = item.customersourcetype
          if (item.clientdept !== null && item.clientdept !== '') {
            tempClientDept = item.clientdept
          }
        } else {
          if (item.clientname !== null && item.clientname !== '') {
            tempClientName = tempClientName + ',' + item.clientname
          }
          if (item.clientdept !== null && item.clientdept !== '') {
            tempClientDept = tempClientDept + ',' + item.clientdept
          }
          tempClientCode = tempClientCode + ',' + item.clientcode
          tempClientSourcetype = tempClientSourcetype + ',' + item.customersourcetype
        }
      })
      if (tempClientName === '') {
        tempClientName = ' '
      }
      if (tempClientDept === '') {
        tempClientDept = ' '
      }
      this.$set(this.model, 'clientcode2', tempClientCode)
      this.$set(this.model, 'clientname2', tempClientName)
      this.$set(this.model, 'clientsourcetype2', tempClientSourcetype)
      this.$set(this.model, 'clientdept2', tempClientDept)
    },
    /** 打开调整项目级别的弹框 **/
    openChangeLevelDialog() {
      this.$refs.changeLevelRef.projectlevelList = this.codeModel.projectlevelList
      this.$refs.changeLevelRef.dispprojectdefaultlevel = this.codeModel.projectlevelList.find((item) => item.code === this.model.originalprojectlevel).name
      this.$set(this.$refs.changeLevelRef.model, 'projectlevel', this.model.projectlevel2)
      this.$set(this.$refs.changeLevelRef.model, 'dispprojectlevel', this.codeModel.projectlevelList.find((item) => item.code === this.model.projectlevel2).name)
      this.$set(this.$refs.changeLevelRef.model, 'changelevelreason', this.model.changelevelreason2)
      this.$refs.changeLevelRef.visible = true
    },
    /** 填写调整项目等级原因后回写数据 **/
    confirmChangeLevel(data) {
      this.$set(this.model, 'projectlevel2', data.projectlevel)
      this.$set(this.model, 'changelevelreason2', data.changelevelreason)
    },
    afterSubmit() {
      this.loaded()
    },
    /** 抽屉组件必有 **/
    resizeHandler() {
      this.mainHeight = document.body.getBoundingClientRect().height - 100 - (this.isApproval ? 110 : 0)
    },
    /** 抽屉组件必有 **/
    doCancelEdit() {
      this.visible = false
      this.$emit('close')
      this.$emit('refresh')
    },
    /** 抽屉组件必有 **/
    formatDate(date) {
      return formatDate(new Date(date ? date.toString().replace(/\-/g, '/') : date), 'yyyy-MM-dd')
    },
    /** 点击左侧导航，抽屉组件必有 **/
    clickNav(code) {
      this.navList.forEach((m) => {
        if (m.code === code) {
          m.on = true
        } else {
          m.on = false
        }
      })
      let element = document.getElementById(code)
      if (element === null) return
      let goY = element.getBoundingClientRect().y - 75
      this.mainScrollElement.scrollTop += goY
    },
    /** 页面滚动时，动态改变左侧导航选中的元素，抽屉组件必有 **/
    onMainScroll() {
      this.mainScrollElement.addEventListener('scroll', () => {
        let currentTop = this.mainScrollElement.scrollTop
        let code = ''
        for (let element of document.getElementsByClassName('step-position')) {
          if (element.getBoundingClientRect().y >= 0) {
            code = element.id
            break
          }
        }
        this.navList.forEach((m) => {
          if (m.code === code) {
            m.on = true
          } else {
            m.on = false
          }
        })
      })
    },
    /** 修改项目来源时将机会点/线索编号、项目名称、项目金额、默认等级、级别调整原因和其他中间变量清空 **/
    changeSource(select) {
      this.$set(this.model, 'chanceclue2', '')
      this.$set(this.model, 'projectname2', '')
      this.$set(this.model, 'participatemoney2', '')
      this.$set(this.model, 'projectdefaultlevel2', '')
      this.$set(this.model, 'changelevelreason2', '')
      this.$set(this.model, 'projectlevel2', '')
      this.$set(this.model, 'productlist', [])
      this.$set(this.model, 'productoutlist', [])
    },
    openMeetDialog(val, editForm) {
      this.navList = []
      this.constNavList.forEach((item) => this.navList.push(item))
      if (val === '1') {
        this.navList.splice(0, 0, { name: '会议决策记录', on: false, code: 'ceomeetresolution' })
      } else {
        this.navList.splice(this.navList.findIndex((item) => item.code === 'ceomeetresolution'), 1)
      }
      // 保存审批类型
      const { id, ceoapprovaltype2, deptcode } = this.model
      const param = { id, ceoapprovaltype2, deptcode }
      putAction(this.url.edit, param).then((res) => {
        if (!res.success) {
          this.$tap.alert(res.message, 'warning')
        }
      })
    },
    /* 退回修改节点调用*/
    saveReviseInfo(resolve, reject) {
      // 拼接挂网开标日期
      // this.$refs.projectBidDate.model.projectDateList.filter(item => item.projectbidbegindate && item.projectbidenddate)
      // this.$set(this.model, 'projectBidDate', this.$refs.projectBidDate.model.projectDateList)
      putAction(this.url.edit, this.model)
        .then((res) => {
          if (res.success) {
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            reject()
          }
        })
        .catch((err) => {
          this.$tap.alert('保存审批类型信息失败，请联系系统管理员', 'warning')
          reject()
        })
    },
    /** PMO审批前调用 **/
    saveChangeApprovalTypeInfoPMO(resolve, reject) {
      // if (!this.$refs.projectBidDate.validateBidDate()) {
      //   this.$tap.alert('请填写挂网日期和开标日期', 'warning')
      //   reject()
      // }
      this.$refs.pmodealform.validate((valid) => {
        if (!valid) {
          this.$tap.alert('请完善必填信息！', 'warning')
          reject()
        }
      })
      const { id, approvaltype2, deptcode } = this.model
      if (!approvaltype2) {
        this.$tap.alert('请选择审批类型')
        reject()
      } else {
        // 拼接挂网开标日期
        // this.$refs.projectBidDate.model.projectDateList.filter(item => item.projectbidbegindate && item.projectbidenddate)
        // this.$set(this.model, 'projectBidDate', this.$refs.projectBidDate.model.projectDateList)
        putAction(this.url.edit, this.model)
          .then((res) => {
            if (res.success) {
              resolve()
            } else {
              this.$tap.alert(res.message, 'warning')
              reject()
            }
          })
          .catch((err) => {
            this.$tap.alert('保存审批类型信息失败，请联系系统管理员', 'warning')
            reject()
          })
      }
    },
    saveChangeApprovalTypeInfoCEO(resolve, reject) {
      const { id, ceoapprovaltype2, deptcode } = this.model
      if (!ceoapprovaltype2) {
        this.$tap.alert('请选择审批类型')
        reject()
      } else {
        const param = { id, ceoapprovaltype2, deptcode }
        putAction(this.url.edit, param)
          .then((res) => {
            if (res.success) {
              if (ceoapprovaltype2 == '0' || (ceoapprovaltype2 == '1' && this.$refs.meetlist.uploaded)) {
                resolve()
              } else {
                this.$tap.alert('请上传会议纪要', 'warning')
                reject()
              }
            } else {
              this.$tap.alert(res.message, 'warning')
            }
          })
          .catch((err) => {
            this.$tap.alert('保存审批类型信息失败，请联系系统管理员', 'warning')
            reject()
          })
      }
    },
    /** 林总邀请审批 **/
    saveInviteInfo(resolve, reject) {
      // 林总邀请审批这个节点，既要选择项目级别，也要选择决策组人员
      // 校验邀请决策的人员是否重复
      const { decisionusercode2, invitedecisionusercode2, projectlevel2 } = this.model
      // 项目级别必须选择，决策组人员不是必须选的
      if (projectlevel2 === '' || projectlevel2 === undefined) {
        this.$tap.alert('请选择项目级别！', 'warning')
        reject()
      } else {
        let flag = false
        if (decisionusercode2 && invitedecisionusercode2) {
          let decisionusercodeArray = decisionusercode2.split(',')
          let invitedecisionusercodeArray = invitedecisionusercode2.split(',')
          flag = decisionusercodeArray.find((item) => (item ? invitedecisionusercodeArray.indexOf(item) >= 0 : false))
          if (flag) {
            this.$tap.alert('邀请决策的人员和原决策组人员重复，请重新选择！', 'warning')
            reject()
          } else {
            // 把邀请决策的人员添加进原决策组人员
            this.model.decisionusercode2 = this.model.decisionusercode2 + this.model.invitedecisionusercode2.substring(1)
            this.model.decisionusername2 = this.model.decisionusername2 + ',' + this.model.invitedecisionusername2
          }
        }
        if (!flag) {
          // this.$refs.projectBidDate.model.projectDateList.filter(item => item.projectbidbegindate && item.projectbidenddate)
          // this.$set(this.model, 'projectBidDate', this.$refs.projectBidDate.model.projectDateList)
          putAction(this.url.edit, this.model)
            .then((res) => {
              if (res.success) {
                this.$emit('refresh')
                resolve()
              } else {
                this.$tap.alert(res.message, 'warning')
                reject()
              }
            })
            .catch((err) => {
              this.$tap.alert('添加邀请决策失败，请联系系统管理员', 'warning')
              reject()
            })
        }
      }
    },
    /** 林总审批 **/
    saveProjectLevelInfo(resolve, reject) {
      const { id, projectlevel2, deptcode } = this.model
      if (projectlevel2 !== this.model.originalprojectlevel) {
        const data = {
          id: id,
          newprojectlevel: projectlevel2,
          oldprojectlevel: this.model.originalprojectlevel
        }
        postAction('/mpm/projectChange/updateLevelHistory', data).then((res) => {
          if (res.success) {
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            reject()
          }
        })
      }
      const param = {
        id,
        projectlevel2,
        deptcode
      }
      putAction(this.url.edit, param)
        .then((res) => {
          if (res.success) {
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            reject()
          }
        })
        .catch((err) => {
          this.$tap.alert('修改项目级别信息失败，请联系系统管理员', 'warning')
          reject()
        })
    },
    /** 获取项目等级，例网级、省级 **/
    getMaxLevel() {
      let param = {
        currentPage: 1,
        pageSize: 500,
        projectsource: this.model.projectsource2,
        sidx: 'sortcode',
        sord: 'asc',
        usercode: this.user.code
      }
      getAction(this.url.changeList, param).then((res) => {
        if (res.success) {
          // 当前用户已选择的线索/机会点
          let codes = this.model.chanceclue2.split(',')
          // 当前用户所有的线索/机会点
          res.result.dataList.forEach((item) => {
            if (codes.find((code) => code === item.CODE)) {
              // 取客户等级最大的作为项目等级
              this.maxLevel = Math.max(this.maxLevel, Number(item.CLIENT_LEVEL))
            }
          })
        } else {
          this.$tap.alert('获取线索/机会点列表错误，请联系管理员')
        }
      })
    },
    changeDeptname() {
      this.model.deptname1 = this.deptname[0]
      this.model.deptname2 = this.deptname[1] || null
      this.model.deptname3 = this.deptname[2] || null
    },
    // 保存之前获取挂网开标日期子表信息
    // beforeSubmit() {
    //   // this.$refs.projectBidDate.model.projectDateList.filter(item => {item.projectbidbegindate && item.projectbidenddate})
    //   // this.$set(this.model, 'projectBidDate', this.$refs.projectBidDate.model.projectDateList)
    //   return true
    // },
    // 删除公司产品
    deleteProductRange(index) {
      if (this.model.productlist.length === 1) {
        this.$tap.alert('内部产品数量为1时，不允许删除')
      } else {
        this.model.productlist.splice(index, 1)
      }
    },
    // 删除非公司产品
    deleteOutProductRange(index) {
      if (this.model.productoutlist.length === 1) {
        this.$tap.alert('外部产品数量为1时，不允许删除')
      } else {
        this.model.productoutlist.splice(index, 1)
      }
    },
    judgeDecisionUser(newLevel) {
      if (!validateNull(this.model.decisionusercode2)) {
        getAction(this.url.judgeDecisionUser, { decisionusercode: this.model.decisionusercode2, decisionusername: this.model.decisionusername2, newlevel: newLevel }).then((res) => {
          if (res.success) {
            this.$set(this.model, 'decisionusercode2', res.result.newdecisionusercode)
            this.$set(this.model, 'decisionusername2', res.result.newdecisionusername)
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      }
    },
    /** 查询编码 */
    doQueryCode() {
      if (this.url.queryCodeList) {
        getAction(this.url.queryCodeList, {}).then((res) => {
          if (res.success) {
            res.result.MpmPurchasePatternList = res.result.MpmPurchasePatternList.filter((item) => Number(item.code) > 10)
            this.codeModel = res.result
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      }
    }
  },
  created() {
    // 抽屉组件必有
    window.addEventListener('resize', this.resizeHandler)
  },
  destroyed() {
    // 抽屉组件必有
    window.removeEventListener('resize', this.resizeHandler)
  }
}
</script>
<style scoped>
.formLine {
  position: relative;
  margin: 0 auto;
  width: 900px;
  height: 1px;
  background-color: #d4d4d4;
  text-align: center;
  font-size: 16px;
  color: rgba(101, 101, 101, 1);
}
.formLineTitle {
  position: absolute;
  left: 12%;
  font-family: 'kaiTi';
  background-color: #ffffff;
  padding: 0 15px;
  transform: translateX(-50%) translateY(-50%);
}
</style>
